using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace InterfaceToPropertyGrid
{
    public partial class Form1 : Form
    {
        private List<Shelf> _shelves;

        public List<Shelf> Shelves
        {
            get { return _shelves; }
            set { _shelves = value; }
        }

        public Form1()
        {
            InitializeComponent();
            this.Shelves = new List<Shelf>();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SetUp();
        }

        private void SetUp()
        {
            //throw new Exception("The method or operation is not implemented.");

            Random r = new Random(43231);
            Shelves.Clear();

            for (int i = 0; i < 10; i++)
            {
                Shelf sh = new Shelf();
                sh.Name = "Shelf " + i.ToString();
                sh.Model = "TestModel " + r.Next(20).ToString();
                sh.Size.Height = r.Next(100);
                sh.Size.Depth = r.Next(100);
                sh.Size.Width = r.Next(100);
                
                Shelves.Add(sh);
                TreeNode tn = new TreeNode();
                tn.Tag = sh;
                tn.Text = sh.ToString();
                this.treeView1.Nodes.Add(tn);

            }

        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //IBizBase shelf = e.Node.Tag as IBizBase;
            //IShelf shelf = e.Node.Tag as IShelf;

            this.propertyGrid1.SelectedObject = new ShelfEditableProjection(e.Node.Tag as IShelf);// shelf;
            //this.propertyGrid1.SelectedObject = shelf;
        }
    }
}